package com.fadis.utils;


import java.util.Arrays;
import java.util.Objects;

public class FadisTuple implements Comparable<FadisTuple> {
    private byte[] element;
    private Double score;

    public FadisTuple(String element, Double score) {
        this(SafeEncoder.encode(element), score);
    }

    public FadisTuple(byte[] element, Double score) {
        this.element = element;
        this.score = score;
    }

    @Override
    public int hashCode() {
        boolean prime = true;
        int result = 1;
        result = 31 * result;
        if (null != this.element) {
            byte[] var3 = this.element;
            int var4 = var3.length;

            for(int var5 = 0; var5 < var4; ++var5) {
                byte b = var3[var5];
                result = 31 * result + b;
            }
        }

        long temp = Double.doubleToLongBits(this.score);
        result = 31 * result + (int)(temp ^ temp >>> 32);
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        } else if (obj == this) {
            return true;
        } else if (!(obj instanceof FadisTuple)) {
            return false;
        } else {
            FadisTuple other = (FadisTuple)obj;
            return !Arrays.equals(this.element, other.element) ? false : Objects.equals(this.score, other.score);
        }
    }

    public int compareTo(FadisTuple other) {
        return compare(this, other);
    }

    public static int compare(FadisTuple t1, FadisTuple t2) {
        int compScore = Double.compare(t1.score, t2.score);
        return compScore != 0 ? compScore : ByteArrayComparator.compare(t1.element, t2.element);
    }

    public String getElement() {
        return null != this.element ? SafeEncoder.encode(this.element) : null;
    }

    public byte[] getBinaryElement() {
        return this.element;
    }

    public double getScore() {
        return this.score;
    }

    public String toString() {
        return '[' + SafeEncoder.encode(this.element) + ',' + this.score + ']';
    }
}